000100******************************************************************
000200*PROGRAM : Change course information                             *
000300*AUTHOR  : Minh-Tuan Ta                                          *
000400******************************************************************
000500 IDENTIFICATION DIVISION.
000600 PROGRAM-ID. CRS-C.
000700 ENVIRONMENT DIVISION.
000800     SELECT IOFILE       ASSIGN TO "CRSMST.DAT"
000900                         ORGANIZATION  IS INDEXED
001000                         ACCESS        IS RANDOM
001100                         RECORD KEY    IS IO-CRS-ID
001200                         FILE STATUS   IS WS-STAT.
001300
001400 DATA DIVISION.
001500 FILE SECTION.
001600 FD  IOFILE.
001700 01  OUT-REC.
001800     03  IO-CRS-ID      PIC X(8).
001900     03  IO-CRS-NAME    PIC X(34).
002000     03  IO-CRS-H       PIC 99.
002100     03  IO-CRS-A       PIC X.
002200
002300 WORKING-STORAGE SECTION.
002400 01  WS-STAT             PIC XX.
002500 01  WS-EOF              PIC X VALUE 'N'.
002600 01  WS-CRS-ID           PIC X(8).
002700 01  WS-CRS-NAME         PIC X(30).
002800 01  WS-CRS-SUBJECT      PIC X(4).
002900 01  WS-CRS-NO           PIC X(4).
003000 01  WS-CRS-H            PIC 9(2).
003100 01  WS-CRS-A            PIC X.
003200 01  WS-DATE.
003300     03  WS-YEAR         PIC 99.
003400     03  WS-MONTH        PIC 99.
003500     03  WS-DAY          PIC 99.
003600 01  WS-ERR              PIC X VALUE 'N'.
003700 01  WS-CONT             PIC X VALUE 'Y'.
       01  WS-CHG              PIC X.
003800
003900 SCREEN SECTION.
004000 01  INPUT-CRS-ID-SCRN.
004100         05  BLANK SCREEN.
004200         05  LINE 1  COL 01  VALUE "CHANGE COURSE".
004300         05          COL 73  PIC 9(2) FROM WS-MONTH.
004400         05          COL 75  VALUE "/".
004500         05          COL 76  PIC 9(2) FROM WS-DAY.
004600         05          COL 78  VALUE "/".
004700         05          COL 79  PIC 9(2) FROM WS-YEAR.
004800         05  LINE 2  COL 37  VALUE "CHANGE COURSE".
               05  INPUT-CRS-SUBJECT-SCRN.
                   10  LINE 5  COL 1   VALUE "COURSE SUBJECT".
005000             10          COL 17  PIC X(4) TO WS-CRS-SUBJECT.
               05  INPUT-CRS-NO-SCRN.
                   10  LINE 6  COL 1   VALUE "COURSE NUMBER".
                   10          COL 17  PIC X(4) TO WS-CRS-NO.
005100         05  LINE 11 COL 34  VALUE "(ENTER XXX TO EXIT)".
005200
005300
005400 01  INPUT-SCRN.
005500         05  BLANK SCREEN.
005600         05  LINE 1  COL 01  VALUE "CHANGE COURSE".
005700         05          COL 73  PIC 9(2) FROM WS-MONTH.
005800         05          COL 75  VALUE "/".
005900         05          COL 76  PIC 9(2) FROM WS-DAY.
006000         05          COL 78  VALUE "/".
006100         05          COL 79  PIC 9(2) FROM WS-YEAR.
006200         05  LINE 2  COL 37  VALUE "CHANGE COURSE".
006300         05  LINE 5  COL 01  VALUE "COURSE ID".
006400         05          COL 17  PIC X(8) FROM IO-CRS-ID.
006500         05  INPUT-CRS-NAME-SCRN.
006600             10  LINE 6  COL 1   VALUE "COURSE NAME".
006700             10          COL 17  PIC X(30) FROM IO-CRS-NAME.
006800             10  LINE 7  COL 17  PIC X(30) TO WS-CRS-NAME.
006900         05  INPUT-CRS-H-SCRN.
007000             10  LINE 8  COL 1   VALUE "CREDIT HOURS".
007100             10          COL 17  PIC 9(2) FROM IO-CRS-H.
007200             10  LINE 9  COL 17  PIC 9(2) TO WS-CRS-H AUTO.
007300         05  INPUT-CRS-A-SCRN.
007400             10  LINE 10  COL 1   VALUE "ACTIVATE (Y/N)?".
007500             10          COL 17  PIC X FROM IO-CRS-A.
007600             10  LINE 11 COL 17  PIC X TO WS-CRS-A AUTO.
007700         05  LINE 14 COL 30  VALUE "(LEAVE BLANK TO KEEP THE OLD V
007800-                "ALUE)".
007900 01  ERROR-SCRN.
008000     03  BLANK SCREEN.
008100     03  LINE 12 COL 32 VALUE "COULD NOT FOUND THIS COURSE ID".
008200     03  LINE 16 COL 32 VALUE "CONTINUE(Y/N)?".
008300     03          COL 47 PIC X TO WS-CONT AUTO.
008400
008500 01  SUCCESS-SCRN.
008600     03  BLANK SCREEN.
008700     03  LINE 12 COL 32 VALUE "RECORD CHANGED SUCCESSFULLY".
008800     03  LINE 13 COL 32 VALUE "RECORD INFORMATION CHANGED TO:".
008900     03  LINE 14 COL 32 VALUE "COURSE ID".
009000     03          COL 46 PIC X(8) FROM IO-CRS-ID.
009100     03  LINE 15 COL 32 VALUE "COURSE NAME".
009200     03          COL 46 PIC X(30) FROM IO-CRS-NAME.
009300     03  LINE 16 COL 32 VALUE "COURSE HOURS".
009400     03          COL 46 PIC 9(2) FROM IO-CRS-H.
009500     03  LINE 17 COL 32 VALUE "ACTIVATE?".
009600     03          COL 46 PIC X FROM IO-CRS-A.
009700     03  LINE 18 COL 32 VALUE "CONTINUE(Y/N)?".
009800     03          COL 47 PIC X TO WS-CONT AUTO.

009100 01  CHG-REC-SCRN.
009200     03  BLANK SCREEN.
009300     03  LINE 4  COL 20  VALUE "COURSE SUBJECT".
009400     03          COL 40  PIC X(4) FROM WS-CRS-SUBJECT.
009500     03  LINE 5  COL 20  VALUE "COURSE NUMBER".
009600     03          COL 40  PIC X(4) FROM WS-CRS-NO.
009700     03  LINE 6  COL 20  VALUE "COURSE NAME".
009800     03          COL 40  PIC X(30) FROM WS-CRS-NAME.
009900     03  LINE 7  COL 20  VALUE "CREDIT HOURS".
010000     03          COL 40  PIC 9(2) FROM WS-CRS-H.
010100     03  LINE 8  COL 20  VALUE "ACTIVATE (Y/N)?".
010200     03          COL 40  PIC X FROM WS-CRS-A.
010300     03  LINE 9  COL 32 VALUE "DO YOU WANT TO CHANGE(Y/N)?".
010400     03          COL 30 PIC X TO WS-CHG AUTO.
010500
010600 01  CONTINUE-SCRN.
010700     03  BLANK SCREEN.
010800     03  LINE 9  COL 32 VALUE "DO YOU WANT TO CONTINUE(Y/N)?".
010900     03          COL 30 PIC X TO WS-CONT AUTO.

009900
010000
010100 PROCEDURE DIVISION.
010200 100-MAIN.
010300     ACCEPT WS-DATE FROM DATE
010400     OPEN I-O IOFILE.
010500
010600     MOVE SPACES TO WS-CRS-ID
010700     MOVE SPACES TO WS-CRS-NAME
010800     MOVE ZEROS TO WS-CRS-H
010900     MOVE SPACES TO WS-CRS-A
011000     MOVE 'Y' TO WS-CONT
011100
011200     DISPLAY INPUT-CRS-ID-SCRN
011300     ACCEPT INPUT-CRS-SUBJECT-SCRN
011400     PERFORM UNTIL WS-CRS-SUBJECT = 'XXX' OR WS-CONT = 'N'

               ACCEPT INPUT-CRS-NO-SCRN

               STRING WS-CRS-SUBJECT DELIMITED BY SIZE
               WS-CRS-NO DELIMITED BY SIZE
               INTO WS-CRS-ID
011500
011600         MOVE WS-CRS-ID TO IO-CRS-ID
011700         READ IOFILE
011800             INVALID KEY MOVE 'Y' TO WS-ERR
011900         END-READ
012000
012100         IF WS-ERR = 'Y'
012200             DISPLAY ERROR-SCRN
012300             ACCEPT ERROR-SCRN
012400         ELSE
012500             DISPLAY INPUT-SCRN
012600             ACCEPT INPUT-CRS-NAME-SCRN
012700             ACCEPT INPUT-CRS-H-SCRN
012800             ACCEPT INPUT-CRS-A-SCRN
012900
013000             IF NOT WS-CRS-NAME = SPACES
013100                 MOVE WS-CRS-NAME    TO IO-CRS-NAME
013200             END-IF
013300
013400             IF NOT WS-CRS-H = ZEROS
013500                 MOVE WS-CRS-H       TO IO-CRS-H
013600             END-IF
013700
013800             IF NOT WS-CRS-A = SPACES
013900                 MOVE WS-CRS-A       TO IO-CRS-A
014000             END-IF
014100
014200

                   DISPLAY CHG-REC-SCRN
                   ACCEPT CHG-REC-SCRN

                   IF WS-CHG = 'Y'

                       MOVE 'N' TO WS-ERR
014300
014400                 REWRITE OUT-REC
014500                     INVALID KEY MOVE 'Y' TO WS-ERR
014600                 END-REWRITE

                       IF WS-ERR = 'Y'
                           DISPLAY ERROR-SCRN
                           ACCEPT ERROR-SCRN
                       ELSE
                           DISPLAY SUCCESS-SCRN
                           ACCEPT SUCCESS-SCRN
                       END-IF

                   ELSE
                       DISPLAY CONTINUE-SCRN
                       ACCEPT CONTINUE-SCRN
                   END-IF
014700
015500         END-IF
015600         IF NOT WS-CONT = 'N'
015700             DISPLAY INPUT-CRS-ID-SCRN
015800             MOVE SPACES TO WS-CRS-ID
015900             MOVE SPACES TO WS-CRS-NAME
016000             MOVE ZEROS TO WS-CRS-H
016100             MOVE SPACES TO WS-CRS-A
016200             MOVE 'N' TO WS-ERR
016300             ACCEPT INPUT-CRS-ID-SCRN
016400         END-IF
016500
016600     END-PERFORM
016700     CLOSE IOFILE
016800     EXIT PROGRAM.
016900
